package com.atguigu.java;

import org.junit.Test;

import java.util.*;

public class CollectionTest {
    @Test
    public void test1(){
        Collection coll = new ArrayList();
        coll.add("aa");
        coll.add("bb");
        coll.add(123);
        coll.add(new Date());
        System.out.println(coll.size());
        Collection coll1 = new ArrayList();
        coll1.add(456);
        coll1.add("cc");
        coll.addAll(coll1);
        System.out.println(coll.size());
        System.out.println(coll);
//        coll.clear();
        System.out.println(coll.size());
        System.out.println(coll.isEmpty());
    }
    @Test
    public void test(){
        Collection coll=new ArrayList();
        coll.add(123);
        coll.add(456);
        Person p=new Person("jerry",20);
        coll.add(p);
        coll.add(new String("tom"));
        coll.add(false);
        boolean contains = coll.contains(123);
        System.out.println(contains);
        System.out.println(coll.contains(new String("tom")));
        System.out.println(coll.contains(p));
        System.out.println(coll.contains(new Person("jerry",20)));
        Collection coll1 = Arrays.asList(123, 456,false);
        System.out.println(coll.containsAll(coll1));


    }
    @Test
    public void test2(){
        Collection coll=new ArrayList();
        coll.add(123);
        coll.add(456);
        Person p=new Person("jerry",20);
        coll.add(p);
        coll.add(new String("tom"));
        coll.add(false);
        coll.remove(123);
        System.out.println(coll);
        coll.remove(new Person("jerry",20));
        System.out.println(coll);
        Collection coll1=Arrays.asList(456,"tom",false);
        coll.removeAll(coll1);
        System.out.println(coll);
    }
    @Test
    public void test3(){
        Collection coll=new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new String("tom"));
        coll.add(false);



        Collection coll1=new ArrayList();
        coll1.add(123);
        coll1.add(456);
        coll1.add(new String("tom"));
        coll1.add(false);
        System.out.println(coll.equals(coll1));
    }
    @Test
    public void test4(){
        Collection coll=new ArrayList();
        coll.add(123);
        coll.add(456);
        Person p=new Person("jerry",20);
        coll.add(p);
        coll.add(new String("tom"));
        coll.add(false);
        System.out.println(coll.hashCode());
        Object[] arr = coll.toArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
            System.out.println("_______________");

            List<String> list = Arrays.asList(new String[]{"aa", "bb", "cc"});
            System.out.println(list);
            List<Integer> arr1=Arrays.asList(123,456);
            System.out.println(arr1);
           List arr3=Arrays.asList(new Integer[]{123,456});
            System.out.println(arr3.size());
            List arr2=Arrays.asList(new int[]{123,455});
            System.out.println(arr2.size());


        }
    }

}
